<?php
namespace catchAdmin\basics\model;

use catchAdmin\basics\model\search\OfficialLogSearch;
use catcher\base\CatchModel;
use think\Exception;
use think\facade\Db;

class OfficialLog extends CatchModel
{
    use OfficialLogSearch;

    protected $name = 'db_official_log';
    protected $field = [
        'id',
        'official_count',
        'articles_count',
        'news_count',
        'news_json',
        'log_type',
        'created_at',
        'updated_at',
        'deleted_at',
        'tenant_id',
        'creator_id'
    ];
    protected $json = [
        'news_json'
    ];
    // 设置JSON数据返回数组
    protected $jsonAssoc = true;

    public function getList($tenant_id = 0)
    {
        $where = [];
        if($tenant_id !== 0){
            $where[]=['tenant_id','=',$tenant_id];
        }

        return $this->withoutField('updated_at,deleted_at')
            ->catchSearch()
            ->where($where)
            ->order($this->aliasField('id'), 'desc')
            ->paginate()
            ->each(function (&$item) {
                //$item['created_at'] = date("Y-m-d",strtotime("today 00:00:00",1635372800));
                $item['created_at_date'] = date("Y-m-d",strtotime($item['created_at']));
            });
    }
}
